<?php
/*
 *      vote.php
 *      
 *      Copyright 2011 unro <unro.ua@gmail.com>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

include ("../inc/core.php");
SESSION();
OpenConn();

$uid = $_SESSION["userID"];
$sid  = $_GET["sid"];
settype($sid, "integer");
$select = mysql_query("SELECT * FROM `vote_var` WHERE `topid`='$sid' AND `userid`='$uid'");
$array = mysql_fetch_array($select);
$current_time = GetDataTime();
$serviseselect = mysql_query("SELECT * FROM `game_top` WHERE `id`='$sid'");
$servisearray = mysql_fetch_array($serviseselect);
$T_bonuses_count = $servisearray["cost"];
$T_link =  $servisearray["link"];
$count = mysql_num_rows($select);
	if ($count == 0)
		{ 
			sleep(1);
			mysql_query("INSERT INTO `vote_var` VALUES ('$sid','$uid','$current_time')");
			DistributeBonuses($uid, $T_bonuses_count);
			MakeLog($_SESSION["userID"],1,$servisearray["name"]);
			header ("Location: $T_link");
		}
	else
		{
			$last_votetime = $array["votetime"];
			$time = GetDataTime(gmtime() - 86400);
			if($last_votetime < $time)
				{
					sleep(1);
					mysql_query("UPDATE `vote_var` SET `votetime`='$current_time' WHERE `topid`='$sid' AND `userid`='$uid'");
					DistributeBonuses($uid, $T_bonuses_count);
					MakeLog($_SESSION["userID"],1,$servisearray["name"]);
					header ("Location: $T_link");
				}
			else { MakeLog($_SESSION["userID"],5); header("Location: ../index.php"); }
		}
?>
